package com.yiwenup.leetcode.top_interview_150;

import java.util.HashMap;
import java.util.Map;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-18 22:30:04
 * @Description https://leetcode.cn/problems/two-sum/description/?envType=study-plan-v2&envId=top-interview-150
 */
public class No0001 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            Integer idx = map.get(target - nums[i]);
            if (idx != null) {
                return new int[]{i, idx};
            }
            map.put(nums[i], i);
        }

        return new int[2];
    }
}
